home *** CD-ROM | disk | FTP | other *** search
- program DTP;
-
- {This program illustrates ways in which "dates.tpu" and "dates.inc" can be
- used. In response to its question "Gimme a date: " you can supply a Day
- Number, a Gregorian date (as mm/dd/yyyy) or a Julian date (as ddd/yyyy).
- Note that the entire year must be given, not just the last two digits.
- The prgram will convert Day Numbers and Julian dates to Gregorian, and will
- validate Gregorian dates, showing you what the back conversion gives.
- To exit the program, just hit ENTER without entering anything.}
-
- {(c)Copyright 1991 Crazy Jack}
- {All Rights Reserved}
- {$A+,B-,D-,F-,R-,S-,V-}
-
- uses
- Dates, {--don't forget this!!!}
- Crt; {---for fastest screen writing.}
-
- var
- N : longint; {Day number holder.}
- Yi, Mi, Di : word; {Holders for month, day, & year input.}
- Yo, Mo, D : word; {Holders for calculated results.}
- EC, X : integer; {Error code and scratch.}
- S : string[47]; {Holds input string.}
-
- {--------------------------YDAY, DOW and MONTHNAME---------------------------}
-
- {$I dates.inc}
-
- {------------------------GET AND ANALYZE USER INPUT--------------------------}
-
- function GetADate : boolean; {Reads a date from the user.}
- begin
- Write('Gimme a date: '); {Pop the question.}
- Readln(S); {Suck up the reply.}
- if Length(S) < 2 {No reply (or one too short)}
- then {Means all done.}
- GetADate := FALSE
- else
- begin {Got something. What???}
- GetADate := TRUE;
- Val(S, N, EC); {Convert first number.}
- if EC > 0 {If no error, we just got one number}
- then {which means a Day Number. Done.}
- begin {--Otherwise we hit a separator.}
- X := EC; {Save its location, then}
- Val(Copy(S,1,EC-1),Mi,EC); {convert number in front. Delete what}
- Delete(S,1,X); {we just converted PLUS the separator.}
- Val(S,Di,EC); {Now try to convert what follows the}
- if EC = 0 {separator. If all is good, we have}
- then {a Julian date.}
- EC := 1 {Show what we found and we're done.}
- else {We must have a Gregorian date.}
- begin
- X := EC; {As before, save location of separator}
- Val(Copy(S,1,EC-1),Di,EC); {Pick up Gregorian month.}
- Delete(S,1,X); {Delete month and the separator.}
- Val(S,Yi,EC); {Convert the year.}
- EC := 2 {Flag "Gregorian date".}
- end
- end
- end
- end; {Aw dun.}
-
- {--------------------------DATE VALIDATION ROUTINES--------------------------}
-
- type
- InS = string[4]; {Used by VI and IV to return result.}
-
- function VI : InS; {Checks a Gregorian date for validity.}
- begin
- VI := ' ';
- if (Mi <> Mo) {Date is invalid if returned month and/or}
- or (Di <> D) {day are not the same.}
- then
- VI := 'n in'
- end;
-
- function IV : InS; {Checks a Julian date for validity.}
- begin
- IV := ' '; {Yo, Mo and D were calculated at the "if"}
- Yi := YDay( Yo, Mo, D ); {preceeding the Writeln where IV is allled.}
- if Yi <> Mi {Date is invalid if returned month and/or}
- then {day are not the same. As a side effect we}
- IV := 'n in' {return correct day of year in Yi to print.}
- end; {Pascal calling sequence makes this work.}
-
- {---------------------------------MAIN LINE----------------------------------}
-
- begin
-
- while GetADate do {Get date from user.}
- begin
-
- if EC = 0 {--means we got a Day Number.}
- then
- if ZDate(N, Yo, Mo, D) {Try converting to Gregorian date.}
- then
- Writeln('Day Number ',N,' is ',DOW( word(N mod 7) ),
- ', ',MonthName(Mo),' ',D,', ',Yo,',',^M^J,
- ' and the Julian date is ',YDay( Yo, Mo, D ),'/',Yo,'.')
- else
- Writeln('Can''t convert Day Number ',N,'.')
-
- else if EC = 1 {--means we got a Julian date.}
- then {NOTE: If we come here, the day of the year}
- begin {is in Mi and the year is in Di!}
- N := Zday(Di, 1, Mi); {Conveert to Day Number,}
- if ZDate(N, Yo, Mo, D) {then convert to Gregorian.}
- then {IV will get the day of the year for us.}
- Writeln('A',IV,'valid Julian date Day Number ',N,' which is ',
- copy(DOW( word(N mod 7) ),1,3),
- ', ',D,' ',copy(MonthName(Mo),1,3),', ',Yo,',',^M^J,
- ' and the Julian date is ',Yi,'/',Yo,'.')
- else
- Writeln('Can''t convert resulting Day Number ',N,'.')
- end
-
- else {--means we got a Gregorian date.}
- begin
- N := ZDay(Yi, Mi, Di); {Convert to Day Number,}
- if ZDate(N, Yo, Mo, D) {then back to Gregorian.}
- then
- Writeln('A',VI,'valid Gregorian date giving Day Number ',N,
- ' which is ',DOW( word(N mod 7) ),', ',Mo,'/',D,'/',Yo,',',^M^J,
- ' and the Julian date is ',YDay( Yo, Mo, D ),'/',Yo,'.')
- else
- Writeln('Can''t convert that date.')
- end;
-
- end
-
- end.
-